package bma.common.mq.outer.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.jdbc.core.JdbcTemplate;

import base.Queue;//TODO
import bma.common.mq.outer.po.Consumer;
import bma.common.mq.outer.po.MessageBase;

public class RegisterServiceImpl {

	private List<Integer> uids = new ArrayList<Integer>();
	private Map<String, MessageBase> messageBases = new ConcurrentHashMap<String, MessageBase>(); //category-messageBase
	private Map<String, ArrayList<Consumer>> msgConsumers = new ConcurrentHashMap<String, ArrayList<Consumer>>(); // category-consumerList
	private Map<Integer, Queue> queues = new ConcurrentHashMap<Integer, Queue>(); // queueId-queue queueId,consumerId一致
	
	/**
	 * 判断该消息类型是否已注册
	 * @param category
	 * @return
	 */
	public boolean hasMessageBase(String category){
		return messageBases.containsKey(category);
	}
	
	/**
	 * 根据消息类型查找元消息
	 * @param category
	 * @return
	 */
	public MessageBase getMessageBase(String category){
		return messageBases.get(category);
	}

	/**
	 * 查找元消息对应的消费者列表（消息类型与元消息一一对应）
	 * @param category
	 * @return
	 */
	public ArrayList<Consumer> getConsumers(String category) {
		return msgConsumers.get(category);
	}

	public Queue getQueue(Integer queueId){
		return queues.get(queueId);
	}
	
	public boolean isUidExist(String uid){
		return uids.contains(uid);
	}

	
	public Map<Integer, Queue> getQueues() {
		return queues;
	}

	/**
	 * JdbcTemplate对象
	 */
	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	
}
